package c.e.a.b.f.b;

import c.e.a.b.e.c.a1;

/* compiled from: com.google.android.gms:play-services-measurement@@18.0.0 */
public final class ca {
    public a1 a;
    public Long b;
    public long c;
    public final /* synthetic */ ba d;

    public ca(ba baVar, aa aaVar) {
        this.d = baVar;
    }

    /* JADX WARNING: Removed duplicated region for block: B:51:0x00f8  */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x00f8  */
    /* JADX WARNING: Removed duplicated region for block: B:78:0x01c0  */
    /* JADX WARNING: Removed duplicated region for block: B:48:0x00f2  */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x00f8  */
    public final c.e.a.b.e.c.a1 a(java.lang.String r19, c.e.a.b.e.c.a1 r20) {
        /*
        r18 = this;
        r1 = r18;
        r3 = r19;
        r8 = r20;
        r0 = r20.F();
        r9 = r20.v();
        r2 = r1.d;
        r2.m();
        r2 = "_eid";
        r4 = c.e.a.b.f.b.q9.R(r8, r2);
        r4 = (java.lang.Long) r4;
        r5 = 1;
        r10 = 0;
        if (r4 == 0) goto L_0x0021;
    L_0x001f:
        r6 = 1;
        goto L_0x0022;
    L_0x0021:
        r6 = 0;
    L_0x0022:
        if (r6 == 0) goto L_0x002e;
    L_0x0024:
        r7 = "_ep";
        r7 = r0.equals(r7);
        if (r7 == 0) goto L_0x002e;
    L_0x002c:
        r7 = 1;
        goto L_0x002f;
    L_0x002e:
        r7 = 0;
    L_0x002f:
        r11 = 0;
        if (r7 == 0) goto L_0x01c4;
    L_0x0033:
        r0 = r1.d;
        r0.m();
        r0 = "_en";
        r0 = c.e.a.b.f.b.q9.R(r8, r0);
        r13 = r0;
        r13 = (java.lang.String) r13;
        r0 = android.text.TextUtils.isEmpty(r13);
        r6 = 0;
        if (r0 == 0) goto L_0x0056;
    L_0x0048:
        r0 = r1.d;
        r0 = r0.d();
        r0 = r0.g;
        r2 = "Extra parameter without an event name. eventId";
        r0.b(r2, r4);
        return r6;
    L_0x0056:
        r0 = r1.a;
        if (r0 == 0) goto L_0x006c;
    L_0x005a:
        r0 = r1.b;
        if (r0 == 0) goto L_0x006c;
    L_0x005e:
        r14 = r4.longValue();
        r0 = r1.b;
        r16 = r0.longValue();
        r0 = (r14 > r16 ? 1 : (r14 == r16 ? 0 : -1));
        if (r0 == 0) goto L_0x011b;
    L_0x006c:
        r0 = r1.d;
        r7 = r0.q();
        r7.g();
        r7.n();
        r0 = r7.t();	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r14 = "select main_event, children_to_process from main_event_params where app_id=? and event_id=?";
        r15 = 2;
        r15 = new java.lang.String[r15];	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r15[r10] = r3;	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r16 = java.lang.String.valueOf(r4);	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r15[r5] = r16;	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r14 = r0.rawQuery(r14, r15);	 Catch:{ SQLiteException -> 0x00e3, all -> 0x00df }
        r0 = r14.moveToFirst();	 Catch:{ SQLiteException -> 0x00dd }
        if (r0 != 0) goto L_0x00a3;
    L_0x0093:
        r0 = r7.d();	 Catch:{ SQLiteException -> 0x00dd }
        r0 = r0.n;	 Catch:{ SQLiteException -> 0x00dd }
        r15 = "Main event not found";
        r0.a(r15);	 Catch:{ SQLiteException -> 0x00dd }
        r14.close();
        r0 = r6;
        goto L_0x00f6;
    L_0x00a3:
        r0 = r14.getBlob(r10);	 Catch:{ SQLiteException -> 0x00dd }
        r15 = r14.getLong(r5);	 Catch:{ SQLiteException -> 0x00dd }
        r15 = java.lang.Long.valueOf(r15);	 Catch:{ SQLiteException -> 0x00dd }
        r6 = c.e.a.b.e.c.a1.M();	 Catch:{ IOException -> 0x00c9 }
        r0 = c.e.a.b.f.b.q9.x(r6, r0);	 Catch:{ IOException -> 0x00c9 }
        r0 = (c.e.a.b.e.c.a1.a) r0;	 Catch:{ IOException -> 0x00c9 }
        r0 = r0.l();	 Catch:{ IOException -> 0x00c9 }
        r0 = (c.e.a.b.e.c.u4) r0;	 Catch:{ IOException -> 0x00c9 }
        r0 = (c.e.a.b.e.c.a1) r0;	 Catch:{ IOException -> 0x00c9 }
        r0 = android.util.Pair.create(r0, r15);	 Catch:{ SQLiteException -> 0x00dd }
        r14.close();
        goto L_0x00f6;
    L_0x00c9:
        r0 = move-exception;
        r6 = r7.d();	 Catch:{ SQLiteException -> 0x00dd }
        r6 = r6.f;	 Catch:{ SQLiteException -> 0x00dd }
        r15 = "Failed to merge main event. appId, eventId";
        r10 = c.e.a.b.f.b.q3.s(r19);	 Catch:{ SQLiteException -> 0x00dd }
        r6.d(r15, r10, r4, r0);	 Catch:{ SQLiteException -> 0x00dd }
        r14.close();
        goto L_0x00f5;
    L_0x00dd:
        r0 = move-exception;
        goto L_0x00e5;
    L_0x00df:
        r0 = move-exception;
        r6 = 0;
        goto L_0x01be;
    L_0x00e3:
        r0 = move-exception;
        r14 = 0;
    L_0x00e5:
        r6 = r7.d();	 Catch:{ all -> 0x01bc }
        r6 = r6.f;	 Catch:{ all -> 0x01bc }
        r7 = "Error selecting main event";
        r6.b(r7, r0);	 Catch:{ all -> 0x01bc }
        if (r14 == 0) goto L_0x00f5;
    L_0x00f2:
        r14.close();
    L_0x00f5:
        r0 = 0;
    L_0x00f6:
        if (r0 == 0) goto L_0x01ad;
    L_0x00f8:
        r6 = r0.first;
        if (r6 != 0) goto L_0x00fe;
    L_0x00fc:
        goto L_0x01ad;
    L_0x00fe:
        r6 = (c.e.a.b.e.c.a1) r6;
        r1.a = r6;
        r0 = r0.second;
        r0 = (java.lang.Long) r0;
        r6 = r0.longValue();
        r1.c = r6;
        r0 = r1.d;
        r0.m();
        r0 = r1.a;
        r0 = c.e.a.b.f.b.q9.R(r0, r2);
        r0 = (java.lang.Long) r0;
        r1.b = r0;
    L_0x011b:
        r6 = r1.c;
        r14 = 1;
        r6 = r6 - r14;
        r1.c = r6;
        r0 = (r6 > r11 ? 1 : (r6 == r11 ? 0 : -1));
        if (r0 > 0) goto L_0x0156;
    L_0x0126:
        r0 = r1.d;
        r2 = r0.q();
        r2.g();
        r0 = r2.d();
        r0 = r0.n;
        r4 = "Clearing complex main event info. appId";
        r0.b(r4, r3);
        r0 = r2.t();	 Catch:{ SQLiteException -> 0x0149 }
        r4 = "delete from main_event_params where app_id=?";
        r5 = new java.lang.String[r5];	 Catch:{ SQLiteException -> 0x0149 }
        r6 = 0;
        r5[r6] = r3;	 Catch:{ SQLiteException -> 0x0149 }
        r0.execSQL(r4, r5);	 Catch:{ SQLiteException -> 0x0149 }
        goto L_0x0165;
    L_0x0149:
        r0 = move-exception;
        r2 = r2.d();
        r2 = r2.f;
        r3 = "Error clearing complex main event";
        r2.b(r3, r0);
        goto L_0x0165;
    L_0x0156:
        r0 = r1.d;
        r2 = r0.q();
        r5 = r1.c;
        r7 = r1.a;
        r3 = r19;
        r2.Q(r3, r4, r5, r7);
    L_0x0165:
        r0 = new java.util.ArrayList;
        r0.<init>();
        r2 = r1.a;
        r2 = r2.v();
        r2 = r2.iterator();
    L_0x0174:
        r3 = r2.hasNext();
        if (r3 == 0) goto L_0x0193;
    L_0x017a:
        r3 = r2.next();
        r3 = (c.e.a.b.e.c.c1) r3;
        r4 = r1.d;
        r4.m();
        r4 = r3.B();
        r4 = c.e.a.b.f.b.q9.w(r8, r4);
        if (r4 != 0) goto L_0x0174;
    L_0x018f:
        r0.add(r3);
        goto L_0x0174;
    L_0x0193:
        r2 = r0.isEmpty();
        if (r2 != 0) goto L_0x019e;
    L_0x0199:
        r0.addAll(r9);
        r9 = r0;
        goto L_0x01ab;
    L_0x019e:
        r0 = r1.d;
        r0 = r0.d();
        r0 = r0.g;
        r2 = "No unique parameters in main event. eventName";
        r0.b(r2, r13);
    L_0x01ab:
        r0 = r13;
        goto L_0x0206;
    L_0x01ad:
        r0 = r1.d;
        r0 = r0.d();
        r0 = r0.g;
        r2 = "Extra parameter without existing main event. eventName, eventId";
        r0.c(r2, r13, r4);
        r2 = 0;
        return r2;
    L_0x01bc:
        r0 = move-exception;
        r6 = r14;
    L_0x01be:
        if (r6 == 0) goto L_0x01c3;
    L_0x01c0:
        r6.close();
    L_0x01c3:
        throw r0;
    L_0x01c4:
        if (r6 == 0) goto L_0x0206;
    L_0x01c6:
        r1.b = r4;
        r1.a = r8;
        r2 = r1.d;
        r2.m();
        r2 = java.lang.Long.valueOf(r11);
        r5 = "_epc";
        r5 = c.e.a.b.f.b.q9.R(r8, r5);
        if (r5 != 0) goto L_0x01dc;
    L_0x01db:
        goto L_0x01dd;
    L_0x01dc:
        r2 = r5;
    L_0x01dd:
        r2 = (java.lang.Long) r2;
        r5 = r2.longValue();
        r1.c = r5;
        r2 = (r5 > r11 ? 1 : (r5 == r11 ? 0 : -1));
        if (r2 > 0) goto L_0x01f7;
    L_0x01e9:
        r2 = r1.d;
        r2 = r2.d();
        r2 = r2.g;
        r3 = "Complex event with zero extra param count. eventName";
        r2.b(r3, r0);
        goto L_0x0206;
    L_0x01f7:
        r2 = r1.d;
        r2 = r2.q();
        r5 = r1.c;
        r3 = r19;
        r7 = r20;
        r2.Q(r3, r4, r5, r7);
    L_0x0206:
        r2 = r20.t();
        r2 = (c.e.a.b.e.c.a1.a) r2;
        r2.p(r0);
        r0 = r2.c;
        if (r0 == 0) goto L_0x0219;
    L_0x0213:
        r2.j();
        r3 = 0;
        r2.c = r3;
    L_0x0219:
        r0 = r2.b;
        r0 = (c.e.a.b.e.c.a1) r0;
        c.e.a.b.e.c.a1.w(r0);
        r0 = r2.c;
        if (r0 == 0) goto L_0x022a;
    L_0x0224:
        r2.j();
        r3 = 0;
        r2.c = r3;
    L_0x022a:
        r0 = r2.b;
        r0 = (c.e.a.b.e.c.a1) r0;
        c.e.a.b.e.c.a1.B(r0, r9);
        r0 = r2.l();
        r0 = (c.e.a.b.e.c.u4) r0;
        r0 = (c.e.a.b.e.c.a1) r0;
        return r0;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.ca.a(java.lang.String, c.e.a.b.e.c.a1):c.e.a.b.e.c.a1");
    }
}
